#!/usr/bin/env python
# -*- encoding: UTF-8 -*-
from __future__ import print_function

from flask_wtf import FlaskForm as Form
from wtforms import StringField, IntegerField, SubmitField,SelectField
from wtforms.validators import DataRequired, IPAddress,NumberRange

def valid_ip():
    return IPAddress(
                    ipv6=False, 
                    message=u"错误的IP地址"
                )


def valid_port():
    return NumberRange(
            min=0,
            max=65535,
            message=u"错误的端口号"
            )

class NewNaoForm(Form):
    nao_name = StringField(
            u'Nao 的名字', 
            validators=[
                DataRequired(u"名字不能为空")
            ])
    ip = StringField(
            u'Nao 的IP地址',
            validators=[valid_ip()]
            )
    port = IntegerField(
            u'Nao 的端口',
            validators=[valid_port()]
            )
    submit = SubmitField(u'提交')

class EditNaoForm(Form):
    nao_name = SelectField(u'Nao 的名字')
    ip = StringField(
            u'Nao 的IP地址',
            validators=[valid_ip()]
            )
    port = IntegerField(
            u'Nao 的端口',
            validators=[valid_port()]
            )
    submit = SubmitField(u'提交')

class SelectNaoForm(Form):
    nao_name = SelectField(u'Nao 的名字')
    submit = SubmitField(u'提交')

class SelectCamForm(Form):
    nao_name = SelectField(u'指定 Nao:')
    position = SelectField(u'相机的位置',
                          choices=[(u'top',u'顶部'),(u'bottom',u'底部')])
    submit = SubmitField(u'提交')


class SaveForm(Form):
    submit = SubmitField(u'保存')

class StopForm(Form):
    submit = SubmitField(u'停止')